package com.jbm.jbmsupplier.activity.address.mode;

import com.jbm.enterapplication.InterfaceMa;
import com.jbm.jbmsupplier.activity.rxjavanet.ModeRxjavaNet;
import com.jbm.onehome.iface.IOrder;
import com.jbm.onehome.iface.Media;

import rx.Observable;
import rx.Observer;
import rx.Subscriber;

/**
 * Created by 家帮忙 on 2017/9/28.
 */

public class MyAddressMode implements  MyAddressInterface {
    @Override
    public void DisposeOrder(final String meible, final String address, final String username, final String desc, final int Mainid, final InterfaceMa interfaceMa) {
        ModeRxjavaNet.Companion.getInstantMode().objects( Observable.create(new Observable.OnSubscribe<IOrder>() {
            @Override
            public void call(Subscriber<? super IOrder> subscriber) {
                subscriber.onNext(ModeRxjavaNet.Companion.getInstantMode().getOhInter().createInOrder(meible,address,username,desc,"estate",Mainid,""));
            }
        })).subscribe(new Observer<IOrder>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
            }

            @Override
            public void onNext(IOrder iOrder) {
                if (iOrder.m_code == 200) {
interfaceMa.onSuccess(iOrder.order_id+"",true);

                }else {
interfaceMa.setError(iOrder.m_info,false);
                }
            }
        });
    }

    @Override
    public void DisposePic(final String orderid, final Media media, final InterfaceMa interfaceMa) {
        ModeRxjavaNet.Companion.getInstantMode().objects( Observable.create(new Observable.OnSubscribe<Media>() {
            @Override
            public void call(Subscriber<? super Media> subscriber) {
                subscriber.onNext(ModeRxjavaNet.Companion.getInstantMode().getOhInter().UploadMedia(Integer.parseInt(orderid), "iorder", media));
            }
        })).subscribe(new Observer<Media>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
            }

            @Override
            public void onNext(Media s) {
                if (s.m_code == 200) {
                    interfaceMa.onSuccess("",true);
                }else {
                    interfaceMa.setError(s.m_info,false);
                }
            }
        });
    }

    @Override
    public void Disposevedio(final String orderid, final Media media, final InterfaceMa interfaceMa) {
        ModeRxjavaNet.Companion.getInstantMode().objects( Observable.create(new Observable.OnSubscribe<Media>() {
            @Override
            public void call(Subscriber<? super Media> subscriber) {
                Media ipc = ModeRxjavaNet.Companion.getInstantMode().getOhInter().UploadMedia(Integer.parseInt(orderid), "iorder", media);
                subscriber.onNext(ipc);
            }
        })).subscribe(new Observer<Media>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
            }

            @Override
            public void onNext(Media s) {
                if (s.m_code == 200) {
                    interfaceMa.onSuccess("",true);

                }else {
                    interfaceMa.setError(s.m_info,false);
                }
            }
        });
    }

    @Override
    public void Disposeaudio(final String orderid, final Media media, final InterfaceMa interfaceMa) {
        ModeRxjavaNet.Companion.getInstantMode().objects( Observable.create(new Observable.OnSubscribe<Media>() {
            @Override
            public void call(Subscriber<? super Media> subscriber) {
                Media ipc = ModeRxjavaNet.Companion.getInstantMode().getOhInter().UploadMedia(Integer.parseInt(orderid), "iorder", media);
                subscriber.onNext(ipc);
            }
        })).subscribe(new Observer<Media>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
            }

            @Override
            public void onNext(Media s) {
                if (s.m_code == 200) {
                    interfaceMa.onSuccess("",true);

                }else {
                    interfaceMa.setError(s.m_info,false);
                }
            }
        });
    }
}
